// components/list-item/list-item.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    index: {  //列表项的索引决定左边的icon颜色
      type: Number,
      value: 0,
    },
    listbox:{
      type:Object,
      value:{
        id:'0',
        name:'',
        checked:false
      }
    },
    editable: {   //是否可编辑
      type: Boolean,
      value: false,
    },
    
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    //选中和取消
    onTap(e){
      let { editable, listbox} = this.data

      let checked = listbox.checked;
      checked = !checked;

      let listbox2 = Object.assign({}, listbox, {checked});
      
      if(!editable) return
      this.setData({
        listbox: listbox2
      })
      this.triggerEvent('custometap', this.data.listbox);  //把checked更新到页面中
    },
  }
})
